<title>系统用户</title>
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>系统管理</cite></a>
    <a><cite>添加用户</cite></a>
  </div>
</div>

<div class="layui-form" lay-filter="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
  <div class="layui-form-item">
    <label class="layui-form-label">登录账号</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" lay-verify="required" name="admin_name" value="{{ d.params.admin_name || '' }}" lay-verify="required" placeholder="登录账号" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">管理组</label>
    <div class="layui-input-inline">
      <div class="layui-input-inline" lay-filter="layadmin-layout-right">
        <select name="group_id" id="parent_id" lay-verify="required">
        </select>
      </div>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">登录密码</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="password" name="admin_pwd" lay-verify="required" placeholder="登录密码" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
      <input type="button" lay-submit lay-filter="LAY-user-back-submit" value="确认" class="layui-btn">
    </div>
  </div>
</div>

<script>
  layui.use(['admin', 'form', 'upload'], function () {
    var $ = layui.$
      , admin = layui.admin
      , form = layui.form
      , upload = layui.upload;
    // 获取分类数据
    admin.req({
      url: layui.setter.api + 'admins/groupList'
      , method: 'get'
      , success: function (data) {
        if (data.code == 0) {
          var info = data.data;
            var html = '<option value="0">选择分组</option>';
          for (var key in info) {
            html += '<option value="' + info[key]['group_id'] + '">' + info[key]['group_name'] + '</option>'
          }
          $("#parent_id").html(html);
          form.render();
        }
      }
    });
//监听提交
      form.on('submit(LAY-user-back-submit)', function(data){
          var field = data.field; //获取提交的字段

          //提交 Ajax 成功后，关闭当前弹层并重载表格
          //提交修改
          admin.req({
              url: layui.setter.api+'admins/add'
              ,data: data.field
              ,method:'post'
              ,success: function(data){
                  if(data.code == 0){
                      location.href="#/admins/";
                      // layui.table.reload('LAY-app-forum-list'); //重载表格
                      // layer.close(index); //执行关闭
                  }else{
                      layer.msg(data.msg);
                  }
              }
          });
      });
  })
</script>